import { useUserStore } from "@/store/modules/user";
import request from "@/utils/request";

const baseURL = "/member/auth";

export const login = (params: LoginForm) =>
  request<Res<LoginResult>>({
    url: `${baseURL}/login`,
    method: "POST",
    data: params,
    noLogin: true,
  });

export const getTokenData = (token: string) =>
  request<Res<LoginResult>>({
    url: `/member/user/get-login-info`,
    method: "GET",
    params: {
      token,
    },
    noLogin: true,
  });

export const refresh = (refreshToken: AuthData["refreshToken"]) => {
  return request<Res<LoginResult>>({
    url: `${baseURL}/refresh-token`,
    method: "POST",
    params: {
      refreshToken,
    },
    noLogin: true,
  });
};

export const logout = () =>
  request<void>({
    url: `${baseURL}/logout`,
    method: "POST",
  });
